﻿Public Class frmNVSetPass
    Public Sub GanTT(ByVal MaNV As String, ByVal TenDangNhap As String)
        Me.txtMaNV.Text = MaNV
        Me.txtTenDangNhap.Text = TenDangNhap
    End Sub
    Dim connect As New connect()
    Private Sub frmNVSetPass_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnChange_Click(sender As System.Object, e As System.EventArgs) Handles btnChange.Click
        If (txtMaNV.Text <> "") Then
            Dim dt As New DataTable
            dt = connect.GetData("select MATKHAU from NHANVIEN where MANV='" + txtMaNV.Text.Trim() + "'")
            If (txtOldPass.Text.Trim() = dt.Rows(0)("MATKHAU").ToString()) Then
                If (txtNewPass.Text = txtReNewPass.Text) Then
                    connect.ExecSql("update NHANVIEN set MATKHAU='" + txtNewPass.Text.Trim() + "' where MANV='" + txtMaNV.Text.Trim() + "'")
                    MessageBox.Show("Đổi Mật Khẩu thành công!")
                    Me.Close()
                Else
                    MessageBox.Show("Mật Khẩu mới chưa trùng khớp!")
                    txtNewPass.Focus()
                    Return
                End If
            Else
                MessageBox.Show("Mật khẩu cũ chưa đúng!")
                txtOldPass.Focus()
                Return
            End If
        Else
            MessageBox.Show("Nhân viên chưa được chọn")
        End If
    End Sub

    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub frmNVSetPass_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            btnChange.PerformClick()
        End If
    End Sub
End Class